package com.examplehub.basics.thread;

import java.util.concurrent.CopyOnWriteArrayList;

public class CopyOnWriteArrayListExample {
  public static void main(String[] args) {
    CopyOnWriteArrayList<Integer> integers = new CopyOnWriteArrayList<>();
    for (int i = 0; i < 10; i++) {
      int finalI = i;
      new Thread(() -> integers.add(finalI)).start();
    }
    try {
      Thread.sleep(1000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    System.out.println(integers);
  }
}
